package com.xcity.game.combat.skill.impl;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.CombatUtils;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 滔滔不绝<br/>
 * 随机对敌方目标造成{0=5#0}回合攻击，每次攻击造成{1=10#0}%技能伤害（每行动一次为1回合，当前行动计算上一次行动回合数）
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90088 extends CombatSkill {

	public COMBAT_SKILL_90088(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		CombatUnit source = action.unit;
		
		int n = (int) skill.getParameter(0) + action.ref().getRound();
		float rate = skill.getParameter(1) / GameStaticConfig.percentBase;
		CombatUnit target = action.target.getUnitRandomly();
		for (int i = 0; i < n; i++) {
			// 拆成n个动作分别执行
			if (target != null && !target.isDied()) {
				ActionEffect effect;
				if (action.getEffects() == null || action.getEffects().isEmpty()) {
					effect = action.addTarget(target);
					target = effect.getUnit(); // 修正目标
				} else {
					Action ref = new Action(source, false);
					action.ref().add(ref);
					effect = ref.addTarget(target);
				}
//				int damage = (int) (source.getMagicPower() * rate - CombatUtils.calcMagicDefenseReduceDamage(effect.getUnit()));
//				damage = CombatUtils.correctDamage(damage);
//				effect.effect(CombatAttribute.Type.HP, -damage);
				CombatUtils.calcMagicAttack(effect, rate);
			}
		}
	}
	
}
